<template>
  <div class="main">
    <el-dialog
      title="编辑"
      :visible="dialogVisible"
      width="30%"
      :before-close="handleClose"
      :close-on-click-modal="false"
    >
      <el-form>
        <el-form-item label="发票代码:" class="form-login-item">
          <el-input
            v-model="invoiceInfo.invoiceCode"
            placeholder="请输入"
          ></el-input
          ><br />
        </el-form-item>
        <el-form-item label="发票号码:" class="form-login-item">
          <el-input
            v-model="invoiceInfo.invoiceNum"
            placeholder="请输入"
          ></el-input
          ><br />
        </el-form-item>
        <el-form-item label="校验码后六位:" class="form-login-item">
          <el-input
            v-model="invoiceInfo.validate"
            placeholder="请输入"
          ></el-input
          ><br />
        </el-form-item>
        <el-form-item label="总金额:" class="form-login-item">
          <el-input
            v-model="invoiceInfo.totalAmount"
            placeholder="请输入"
          ></el-input
          ><br />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleUpdate">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  updateInvoice,
} from "@/service.js";
export default {
  components: {},
  props: {
    currentRowInfo: {
      type:Object,
      default: {}
    },
    dialogVisible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      invoiceInfo: {}
    };
  },
  watch: {
    dialogVisible(newVal, oldVal) {
      if(newVal) {
        this.invoiceInfo = {...this.currentRowInfo};
      }
    }
  },
  computed: {},
  created() {},
  mounted() {},
  methods: {
    handleClose(isRefresh = false) {
      this.$emit('toClose', isRefresh);
    },
    // 调用接口更新当前id发票数据
    async handleUpdate() {
      const params = this.invoiceInfo;
      const res = await updateInvoice(params);
      if (res.data.code === 0) {
        this.handleClose(true);
      }
      this.editDialogVisible = false;
    },
  },
};
</script>
<style lang="scss" scoped>
</style>